9d1056
@@ -36,8 +36,11 @@
import javax.security.auth.callback.NameCallback;
 import javax.security.auth.callback.UnsupportedCallbackException;
 import javax.security.auth.login.LoginException;
 
+import org.jboss.as.core.security.RealmUser;
+import org.jboss.as.core.security.SubjectUserInfo;
 import org.jboss.as.security.logging.SecurityLogger;
 import org.jboss.remoting3.Connection;
+import org.jboss.remoting3.security.UserInfo;
 import org.jboss.remoting3.security.UserPrincipal;
 import org.jboss.security.SimpleGroup;
 import org.jboss.security.auth.callback.ObjectCallback;
@@ -89,13 +92,27 @@
public class RemotingLoginModule extends AbstractServerLoginModule {
         Object credential = getCredential();
         if (credential instanceof RemotingConnectionCredential) {
             Connection con = ((RemotingConnectionCredential) credential).getConnection();
-            UserPrincipal up = null;
-            for (Principal current : con.getPrincipals()) {
-                if (current instanceof UserPrincipal) {
-                    up = (UserPrincipal) current;
-                    break;
+            Principal up = null;
+
+            UserInfo userInfo = con.getUserInfo();
+            if (userInfo instanceof SubjectUserInfo) {
+                for (Principal current : ((SubjectUserInfo) userInfo).getPrincipals()) {
+                    if (current instanceof RealmUser) {
+                        up = current;
+                        break;
+                    }
+                }
+            }
+
+            if (up == null) {
+                for (Principal current : con.getPrincipals()) {
+                    if (current instanceof UserPrincipal) {
+                        up = current;
+                        break;
+                    }
                 }
             }
+
             // If we found a principal from the connection then authentication succeeded.
             if (up != null) {
                 identity = up;
